package indzcraft.ranking;

import fast.mvc.Model;
import indzcraft.loader.Enchant;
import indzcraft.loader.Gem;
import indzcraft.loader.Item;
import indzcraft.loader.Reforge;
import indzcraft.loader.Slot;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class ItemCompare<T> {
	
	Model model;
	Item item;
	ArrayList<T> items;
	Slot slot;
	ArrayList<EP<T>> comparedItems;
	
	public ItemCompare(Model model,Item curItem,ArrayList<T> items,Slot slot){
		this.model = model;
		this.item = curItem;
		this.items = items;
		this.slot = slot;
		comparedItems = new ArrayList<EP<T>>();
		
		Iterator<T> ie = items.iterator();
		while(ie.hasNext()){
			T item = ie.next();
			double ep = 0;
			if(item instanceof Item){
				ep = model.calcItemEP((Item) item, slot);
				((Item) item).setEp(ep);
			}
			else if(item instanceof Gem){
				ep = model.calcGemEP((Gem) item);
				((Gem) item).setEP(ep);
			}
			else if(item instanceof Enchant){
				ep = model.calcEnchantEP((Enchant) item, slot);
				((Enchant) item).setEP(ep);
			}
			else if(item instanceof Reforge){
				ep = model.calcReforgeEP(curItem,(Reforge) item);
				((Reforge) item).setEP(ep);
			}
			comparedItems.add(new EP<T>(item, ep));
		}
		Collections.sort(comparedItems);
		
	}
	
	public ArrayList<EP<T>> getComperator(){		
		return comparedItems;
	}
}
